import type { Module } from 'vuex'
import lkfRequest from '@/services'
import { IRootState } from '../types'
import { ISheetDetail } from './types'
/* 详情store */
const detail: Module<ISheetDetail, IRootState> = {
  namespaced: true,
  state() {
    return {
      sheetDetail: []
    }
  },
  getters: {},
  mutations: {
    getSheetDetailGetter(state, list) {
      /* 歌曲 url 后面传入尺寸参数，请求小尺寸图片，节省性能 */
      for (const item of list.tracks) {
        item.al.picUrl += '?param=200x200'
      }
      state.sheetDetail = list
    }
  },
  actions: {
    /* 请求数据 */
    async getsheetDetailAction({ commit }, payload) {
      const list = await lkfRequest.get({
        url: `/playlist/detail?id=${payload.id}`
      })
      commit('getSheetDetailGetter', list.playlist)
    }
  }
}
export default detail
